var ajaxConfig = config.ajax = {
    defaultSuccessCheck: function(data, status) {
        if (data && !data.Succeed && data.SessionTimeout == 1) {
            alert("会话已经失效，请您重新登录");
            window.location.href = "./";
            return false
        }
        return true
    },
    defaultErrorCallback: function(xhr, status, error) {
        if (xhr.statusText != 'success') {
            alert('showErrorToast' + '请求超时或网络问题,' + status || error);
        }
    },
    getView: getView
};
var templates = jc.templates = {};

function getView(view, callback, errorCallback) {
    $.ajax({
        type: "GET",
        url: config.tplRootUrl + view,
        timeout: 10000,
        cache: false,
        success: function(data, status) {
            if (ajaxConfig.defaultSuccessCheck(data, status)) {
                if (typeof callback == "function") {
                    callback(data);
                }
            }

            // if (data && !data.Succeed && data.SessionTimeout == 1) {
            //     alert("会话已经失效，请您重新登录");
            //     window.location.href = "./";
            //     return;
            // }
        },
        error: function(xhr, status, error) {
            if (errorCallback && (typeof errorCallback == "function")) {
                errorCallback(xhr, status, error);
            } else {
                ajaxConfig.defaultErrorCallback(xhr, status, error)
            }
        }
    });
}

function getBufferedView(view, callback) {
    if (!templates[view]) {
        ajaxConfig.getView(view + ".html", function(data) {
            templates[view] = data;
            callback(data);
        }, function() {
            alert('get view failed');
        });
    } else {
        callback(templates[view]);
    }
}